package tu.j2ee.tasktracker.service;

import java.util.Date;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.stereotype.Service;

import tu.j2ee.tasktracker.dao.CommentDAO;
import tu.j2ee.tasktracker.dao.CustomUserDAO;
import tu.j2ee.tasktracker.domain.Comment;
import tu.j2ee.tasktracker.domain.CustomUser;

@Service
public class CommentService {

	@Autowired
	private CustomUserDAO customUserDao;
	
	@Autowired
	private CommentDAO commentDao;
	
	public Comment save( Comment comment){
		
		String username = SecurityContextHolder.getContext().getAuthentication().getName();
		CustomUser user = customUserDao.findByUsername(username);
		
		comment.setCustomUser(user);
		Date d = new Date();
		comment.setDateCreated(d);
		Comment save = commentDao.save(comment);
		
		return save;
		
	}
}
